<html>
<head><meta charset="utf-8"><title>Attributes are large · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html">Attributes are large</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240122767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240122767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240122767">(May 24 2021 at 22:47)</a>:</h4>
<p>According to some memory profiles I took a while ago, attributes stored in <code>ItemTree</code>s might take up significant space.</p>
<p>I suspect that this is in part due to token trees not using interning or well-known symbols (which would eliminate ~all copies of builtin attribute names).</p>
<p>What would be the right approach to improving this? It seems to me that using <code>hir_def::Name</code> instead of <code>SmolStr</code>s in <code>tt::Ident</code> isn't semantically right. rustc just has <code>Symbol</code>s, which are interned strings without much semantic attached to them.</p>



<a name="240122832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240122832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240122832">(May 24 2021 at 22:48)</a>:</h4>
<p>Also I'm wondering if we could do something about all those duplicated documentation strings here</p>



<a name="240122956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240122956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240122956">(May 24 2021 at 22:49)</a>:</h4>
<p>Interning <code>AttrInput</code> alone saves over 10 MB already, probably because there are a lot of similar-enough attributes like <code>#[cfg(test)]</code></p>



<a name="240161415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240161415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240161415">(May 25 2021 at 09:19)</a>:</h4>
<p>One fun thing to try would be to replace </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">pub</span><span class="p">(</span><span class="k">crate</span><span class="p">)</span><span class="w"> </span><span class="n">path</span>: <span class="nc">Interned</span><span class="o">&lt;</span><span class="n">ModPath</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="p">(</span><span class="k">crate</span><span class="p">)</span><span class="w"> </span><span class="n">input</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">AttrInput</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
</code></pre></div>
<p>with</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">pub</span><span class="p">(</span><span class="k">crate</span><span class="p">)</span><span class="w"> </span><span class="n">raw_text</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
</code></pre></div>
<p>and see how that affects memory usage. I don't have a good intuition about the difference in memory usage between a string and a token tree. I suspect strings might be significantly more memory-efficient.</p>



<a name="240162633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240162633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240162633">(May 25 2021 at 09:33)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> what are you using for heap-profiling, mastiff? Do you think it makes sense to add an xtask for that? Or maybe some docs to the dev/README? I'd love to take a look at profiles myself, but I want to re-use your hard-earned knowledge if possible :)</p>



<a name="240172958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240172958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240172958">(May 25 2021 at 11:26)</a>:</h4>
<p><a href="/user_uploads/4715/cNoRaPCFtlWeIJOHH8hCz6W3/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/cNoRaPCFtlWeIJOHH8hCz6W3/image.png" title="image.png"><img src="/user_uploads/4715/cNoRaPCFtlWeIJOHH8hCz6W3/image.png"></a></div>



<a name="240172980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240172980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240172980">(May 25 2021 at 11:27)</a>:</h4>
<p>new hack to quickly estimate the impact of sizer of things</p>



<a name="240173106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240173106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240173106">(May 25 2021 at 11:28)</a>:</h4>
<p>This changes <code>Item Collection:     1.48s, 15ginstr, 73mb</code> to <code>Item Collection:     1.45s, 15ginstr, 78mb</code> for rowan, so RawAttrs themselves are 5-10% of total memory</p>



<a name="240173121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240173121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240173121">(May 25 2021 at 11:28)</a>:</h4>
<p>which does sound like a lot</p>



<a name="240173154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attributes%20are%20large/near/240173154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attributes.20are.20large.html#240173154">(May 25 2021 at 11:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Attributes.20are.20large/near/240162633">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> what are you using for heap-profiling, mastiff? Do you think it makes sense to add an xtask for that? Or maybe some docs to the dev/README? I'd love to take a look at profiles myself, but I want to re-use your hard-earned knowledge if possible :)</p>
</blockquote>
<p>nowadays I mostly use heaptrack since it's a lot faster than valgrind</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>